// pages/recharge/tixian.js
const app = getApp()
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		userInfo: {},
		mag_balance: '0.00',
		setting:{},
          can_cash:false
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		let that = this;
		app.connect('index/setting', {}, function (res) {
			that.setData({
				setting: res
			})
               console.log(res);
		});

		app.login(function (userInfo) {
			that.setData({
				userInfo: userInfo.data
			})
			//加载麦粒余额
			if (app.isPoneAvailable(that.data.userInfo.mobile)) { //手机号已绑定
				app.connect('account/getMagBalance', {
					uid: that.data.userInfo.uid,
					openid: that.data.userInfo.openId,
					mobile: that.data.userInfo.mobile
				}, function (res) {
					var balance = res.data.balance;
					that.setData({
						mag_balance: parseFloat(balance).toFixed(2)
					});
                         if(that.data.mag_balance >= parseFloat(that.data.setting.cash_limit)) {
                              that.setData({
                                   can_cash:true
                              });
                         }
				});
			}
		});
	},
	/**
	 * 提现申请
	 */
	submit:function(e){
		let that = this;
		var money = e.detail.value.money;
		var address = e.detail.value.address;
		app.connect('account/magTixian',{
			uid:that.data.userInfo.uid,
			openid:that.data.userInfo.openId,
			mobile:that.data.userInfo.mobile,
			money:money,
			address:address
		},function(res) {
			wx.showToast({
				title: res.msg,
				icon:'none'
			})
		});
	}
})